﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Ds.DataBase.Model;

namespace Ds.DataBase.Migrations.SeedData
{
    public class ZhiWeiCreator
    {
        public static List<ZhiWei> ZhiWeis { get; private set; }

        private readonly UserInfoClassContext _context;

        static ZhiWeiCreator()
        {
          
           
        }
        //public ZhiWeiCreator(UserInfoClassContext context)
        //{
        //    _context = context;
        //    ZhiWeis = new List<ZhiWei>()
        //    {
        //        new ZhiWei(){keshi =  _context.KeShiContext.First(s => s.ksmc == "信息科"),SonZhiWeis = new List<ZhiWei>(),zwmc = "主管",PowerTrees = new List<PowerTree>(){ _context.PowerTreesContext.First(s => s.mc == "个人管理")},zwpath = "/"}
        //    };
        //}

        public void Create()
        {
            CreateZhiWeis();
        }

        private void CreateZhiWeis()
        {
            foreach (var language in ZhiWeis)
            {
                AddLanguageIfNotExists(language);
            }
        }

        private void AddLanguageIfNotExists(ZhiWei zhiWei)
        {
            if (_context.ZhiWeiContext.Any(l => l.zwmc == zhiWei.zwmc))
            {
                return;
            }
            _context.ZhiWeiContext.Add(zhiWei);
            _context.SaveChanges();
        }
    }
}
